<?php
defined('IN_TS') or die('Access Denied.');

/* 
 * 淘宝客分类管理
 */

switch($ts) {
	//分类列表
	case "list":
		$arrCate = $new['tbshare']->findAll('tbshare_cates',null,"paixu DESC");
		include template("admin/cate_list");
		break;
	case 'add':
		
		include template("admin/cate_add");
		break;
	case 'edit':
		$cateid = $_GET['cateid'];
		$strCate = $db->once_fetch_assoc("select * from ".dbprefix."tbshare_cates where cateid='$cateid'");

		include template("admin/cate_edit");
		
		break;
	case 'add_do':
		$arrData = array(
			'catename' => trim($_POST['catename']),
			"paixu"	   => intval($_POST['paixu'])
		);
		$cateid = $db->insertArr($arrData,dbprefix.'tbshare_cates');
		header("Location: ".SITE_URL."index.php?app=tbshare&ac=admin&mg=cate&ts=list");
		break;
	//分类修改执行 
	case "edit_do":
		$cateid	  = $_POST['cateid'];
		$catename = $_POST['catename'];
		$paixu	  = intval($_POST['paixu']);
		
		$db->query("update ".dbprefix."tbshare_cates set `catename`='$catename',`paixu`='$paixu' where cateid='$cateid'");
		
		header("Location: ".SITE_URL."index.php?app=tbshare&ac=admin&mg=cate&ts=list");
		
		break;
	//分类删除
	case "del":
		
		$cateid = intval($_GET['cateid']);
		
		$catenum = $db->once_fetch_assoc("SELECT count(1) as  count FROM ".dbprefix."tbshare_cates");
		if($catenum['count'] <= 1) {
			qiMsg('至少保留一个分类');
		}

		$groupNum = $db->once_fetch_assoc("select count(*) from ".dbprefix."tbshare where `cateid`='$cateid'");
		
		if($groupNum['count(*)'] > 0){
			qiMsg("此分类有商品存在，不允许删除！");
		}
		
		$db->query("delete from ".dbprefix."tbshare_cates where cateid='$cateid'");
		
		
		qiMsg("分类删除成功！");
		
		break;
	
}


